//
//  ViewController.m
//  14-礼物说
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"
#import "YMJCollectionReusableView.h"
#import "YMjCollectionViewCell.h"
#import "CircleCollectionReusableView.h"

@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collect;
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    _flowLayout.itemSize = CGSizeMake(185, 185 * 0.6);
    _flowLayout.minimumLineSpacing = 4;
    _flowLayout.minimumInteritemSpacing = 4;
    self.collect = [[UICollectionView alloc] initWithFrame:CGRectMake(20, 0, 374, 736) collectionViewLayout:_flowLayout];
    [self.view addSubview:_collect];
    _collect.backgroundColor = [UIColor whiteColor];
    _collect.delegate = self;
    _collect.dataSource = self;
    [_collect registerClass:[YMjCollectionViewCell class] forCellWithReuseIdentifier:@"1"];
    //分区1-2-3
    [_collect registerClass:[YMJCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"2"];
    
    _dataArray = @[@"栏目",@"品种",@"风格",@"对象"];
    //分区0
    [_collect registerClass:[CircleCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"3"];
    
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(0, 500);
    } else {
        return CGSizeMake(0, 50);
    }
    
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        CircleCollectionReusableView *cell = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"3" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor whiteColor];
        cell.label.text = _dataArray[0];
        return cell;
    } else {
        YMJCollectionReusableView *cell = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"2" forIndexPath:indexPath];
        if (indexPath.section == 1) {
            cell.label.text = _dataArray[1];
        } else if (indexPath.section == 2) {
            cell.label.text = _dataArray[2];
        } else {
            cell.label.text = _dataArray[3];
        }
        return cell;
    }
    
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 4;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }
    return 6;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YMjCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"1" forIndexPath:indexPath];
    if (indexPath.section == 1) {
        cell.myImageView.image = [UIImage imageNamed:@"1000"];
    } else if (indexPath.section == 2) {
        cell.myImageView.image = [UIImage imageNamed:@"1001"];
    } else {
        cell.myImageView.image = [UIImage imageNamed:@"1002"];
    }
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
